from enum import Enum

from devtools import debug
from pydantic import BaseModel, Field, ValidationError

# 使用非字符串的枚举
class MyIntEnum(Enum):
    foo = 1
    bar = 2

class Model(BaseModel):
    x: str = Field(strict=True)

try:
    Model(x=MyIntEnum.foo.value)
except ValidationError as exc:
    print(repr(exc.errors()[0]['type']))
    debug(exc.errors())
    #> 'string_sub_type'